package com.myrock.zlbandy.gorock.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.android.volley.toolbox.ImageLoader;
import com.myrock.zlbandy.gorock.HttpModel.Model.ImageInfo;
import com.myrock.zlbandy.gorock.rock.z.MyRockAPI;
import com.myrock.zlbandy.gorock.rock.tools.NetRequest;
import com.myrock.zlbandy.gorock.rock.tools.LruImageCache;
import com.myrock.zlbandy.gorock.R;
import com.myrock.zlbandy.gorock.my.views.ScaleImageView;

import java.util.ArrayList;

/**
 * Created by zlbandy on 2017/9/11.
 */

public class PhotoAdapter extends BaseAdapter {
    private static final String TAG = "PhotoAdapter";

    //private ImageLoader mLoader;
    private Context context;
    private int layoutId;
    private ArrayList<ImageInfo> listData;
    private int to[];


    public PhotoAdapter(Context context, int layoutId,
                             ArrayList<ImageInfo> listData, int to[]) {
        this.context = context;
        this.layoutId = layoutId;
        this.listData = listData;
        this.to = to;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        PhotoAdapter.ViewHolder holder;

        if (convertView == null) {
            LayoutInflater layoutInflator = LayoutInflater.from(context);
            convertView = layoutInflator.inflate(R.layout.photo_grid, null);
            holder = new PhotoAdapter.ViewHolder();
            holder.imageView = (ScaleImageView) convertView.findViewById(R.id.imageView1);
            convertView.setTag(holder);
        }

        holder = (PhotoAdapter.ViewHolder) convertView.getTag();
        LruImageCache lruImageCache = LruImageCache.instance();
        ImageLoader imageLoader = new ImageLoader(NetRequest.getInstance(context),lruImageCache);
        holder.imageView.setImageUrl(MyRockAPI.IMAGE_API+listData.get(position).getId()+".jpg", imageLoader);
        return convertView;
    }

    static class ViewHolder {
        ScaleImageView imageView;


    }

}
